﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using DSAServer.Utils;

namespace DSAServer.Models.Input
{
    /// <summary>
    /// 微信菜单
    /// </summary>
    public class WeixinMenu
    {
        public string name { get; set; }
        public string url { get; set; }
        public List<WeixinMenu> submenu { get; set; }
    }

    public class WeixinMenuUtils
    {
        private static List<WeixinMenu> menuList;
        public static List<WeixinMenu> Instance
        {
            get
            {
                if (menuList == null)
                {
                    menuList = new List<WeixinMenu>();
                    try
                    {
                        StreamReader rsf = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "\\App_Data\\menu.dat");
                        string strConfig = "";
                        while (rsf.Peek() >= 0)
                        {
                            strConfig += rsf.ReadLine();
                        }
                        rsf.Close();
                        menuList = JsonHelper.DeserializeObject<List<WeixinMenu>>(strConfig);
                    }
                    catch (IOException e)
                    {
                        Console.WriteLine(e.ToString());
                    }
                }
                return menuList;
            }
        }
    }
}